package com.kelp.codetoolkit.actions

import com.intellij.database.psi.DbTable
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.LangDataKeys
import com.intellij.openapi.ui.Messages
import com.kelp.codetoolkit.ui.form.DatabaseToCodeFormDialog
import com.kelp.codetoolkit.utils.CacheDataUtil

/**
 * @author: liuyuebai
 * @date: 2024/7/30 18:01
 * @description:
 */
class DatabaseToCodeToolkitAction: AnAction() {

    override fun actionPerformed(e: AnActionEvent) {
        val project = e.project
        if (project != null) {
            val psiElement  = e.getData(LangDataKeys.PSI_ELEMENT)
            var selectTable:DbTable? = null
            if(psiElement is DbTable ) {
                selectTable = psiElement
            }
            if (null == selectTable) {
                Messages.showErrorDialog("Please select the table structure for file creation.","Error")
                return
            }
            CacheDataUtil.setDbTable(selectTable)
            DatabaseToCodeFormDialog(project).show()
        }
    }


}